package com.ljf.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ljf.annotation.HasPermission;
import com.ljf.dto.StoreQueryDto;
import com.ljf.entity.Store;
import com.ljf.service.StoreService;
import com.ljf.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/inventory_management/store")
public class StoreController {

    @Autowired
    private StoreService storeService;

    @HasPermission("inventory_management:store:save")
    @PostMapping("/save")
    public Result saveStore(Store store){
        storeService.saveStore(store);
        return Result.success();
    }
    /*修改仓库接口*/
    @HasPermission("inventory_management:store:update")
    @PostMapping("/update")
    public Result updateStore(Store store){
        storeService.updateStore(store);
        return Result.success();
    }
    /*停用仓库*/
    @HasPermission("inventory_management:store:deactivate")
    @PostMapping("/deactivate")
    public Result deactivate(Long sid){
        storeService.deactivate(sid);
        return Result.success();
    }

    /*查询仓库信息*/
    @HasPermission("inventory_management:store:list")
    @PostMapping("/list")
    public Result list(StoreQueryDto dto){
        return Result.success(storeService.list( new QueryWrapper<Store>()
                .like(StringUtils.hasText(dto.getName()),"name",dto.getName())
                .eq(StringUtils.hasText(dto.getState()),"state",dto.getState())
        ));
    }
}
